

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.plaf.basic.BasicDesktopIconUI;

public class Test2 {
	public static void main(String[] args) {
		try {
			JFrame frame = new JFrame();
			frame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
			JDesktopPane pane = new JDesktopPane();
			JInternalFrame iFrame = new JInternalFrame("Internal Frame",true,true,true,true);
			iFrame
					.setFrameIcon(new ImageIcon(ImageIO.read(new java.net.URL(
							Test2.class.getResource("Raod.jpg"),
							"Raod.jpg"))));
			iFrame.getDesktopIcon().setUI(
					new MyDesktopIconUI("Iconified Internal Frame", iFrame
							.getFrameIcon()));
			iFrame.setIconifiable(true);
			iFrame.setSize(200, 200);
			iFrame.setVisible(true);
			pane.add(iFrame);
			pane.setPreferredSize(new Dimension(500, 500));
			frame.add(pane);
			frame.pack();
			frame.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static class MyDesktopIconUI extends BasicDesktopIconUI {
		private JLabel textLabel;
		private JLabel iconLabel;

		public MyDesktopIconUI(String text, Icon icon) {
			textLabel = new JLabel(text);
			iconLabel = new JLabel(icon);
		}

		protected void installComponents() {
			desktopIcon.setLayout(new BorderLayout());
			desktopIcon.add(iconLabel, BorderLayout.WEST);
			desktopIcon.add(textLabel, BorderLayout.EAST);
		}

		protected void uninstallComponents() {
			desktopIcon.remove(textLabel);
			desktopIcon.remove(iconLabel);
			desktopIcon.setLayout(null);
		}
	}
}
